﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Caliburn.PresentationFramework.ApplicationModel;
using HRManager.ViewModels;
using Spring.Context.Support;
using Caliburn.Spring;
using Spring.Data.Config;
using Spring.Objects.Factory.Xml;

namespace HRManager
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        public App()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Startup with ShellViewModel
        /// </summary>
        /// <returns>
        /// The ShellViewModel instance
        /// </returns>
        protected override object CreateRootModel()
        {
            var binder = (DefaultBinder)Container.GetInstance<IBinder>();
            binder.EnableMessageConventions();
            binder.EnableBindingConventions();

            return Container.GetInstance<ShellViewModel>();
        }

        /// <summary>
        /// Overrider default container with Spring Container
        /// </summary>
        /// <returns>
        /// The Spring container
        /// </returns>
        protected override Microsoft.Practices.ServiceLocation.IServiceLocator CreateContainer()
        {
            NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
            var context = new GenericApplicationContext();
            var objDefinition = new XmlObjectDefinitionReader(context);
            objDefinition.LoadObjectDefinitions("assembly://" + typeof(App).Assembly.FullName +
                                                "/HRManager/HRManager.ctx.xml");
            return new SpringAdapter(context);
        }
    }
}
